package chamans.webphp{
import flash.display.*;
import flash.events.*;
import flash.filters.*;

public class Button  extends Sprite {
private var style:*
private var B:SimpleButton
private var Target:*
public function Button (S:*, T:*, OBJ:*, F:Function, x:int, y:int, color:Array, w:int=60, h:int=26):void{
      style=S
	  B = new SimpleButton();
      B.upState = ButtonState( color[0], T, 1 , w, h,0);
      B.overState = ButtonState( color[1], T, 2 , w, h,10);
      B.downState = ButtonState( color[2], T, 3 ,w, h, 0 );
      B.hitTestState = B.upState;
      B.x = x;   B.y = y;
      B.addEventListener( MouseEvent.CLICK, F );
      Target=OBJ
      Target.addChild( B )
}
private function FILTER(OBJ:*):void{
	OBJ.filters = [ new DropShadowFilter( -1, 45, 0x000000, .8, 2, 2, 1, 1 ) ,new BevelFilter(5, 45, 0x000000, 0.6, 0xFFFFFF, 0.6, 14, 14, 1,1, "inner", false)]; 
	}
private function ButtonState(color:uint, T:*, N:uint, w:int=80, h:int=30,z:int=0):Sprite 
{
      var state:MovieClip = new MovieClip();  
	 
      var background:Sprite =Rcarre( color, 1, w, h, 5 )
	//  
     if (N==1) background.filters = [ new DropShadowFilter( 1, 45, 0x000000, .4, 2, 2, 1, 1 ) ,new BevelFilter(1, 45, 0xFFFFFF, 0.3, 0xeeeeee, 0.3, 2, 2, 1,2, "inner", false)];
     if (N==2) background.filters = [ new DropShadowFilter( 2, 45, 0x000000, .8, 5, 5, 1, 1 ) ,new BevelFilter(5, 45, 0xFFFFFF, 0.6, 0x000000, 0.6, 14, 14, 1,2, "inner", false)];
     if (N==3) background.filters = [ new DropShadowFilter( -2, 45, 0x000000, .8, 2, 2, 1, 1 ) ,new BevelFilter(5, 45, 0x000000, 0.6, 0xFFFFFF, 0.6, 14, 14, 1,2, "inner", false)];    
      state.addChild( background );
	
      if(T as String){
	  var  xml8:XML=<xml><button></button></xml>; xml8.button=T
	  var label:txt=new txt({ text:xml8, target:this, style:style, width:w,height:30,  x:0, y:2 })
	  label.TX.filters = [ new DropShadowFilter( -1, 45, 0x000000, .8, 2, 2, 1, 1 )]
	  var tmpb:Bitmap=bitmap( label.TX )
	  label.clear()
	  state.addChild( tmpb )
	  }
	    else {
		      var P:*=new T();
			  P.x=(w>>1)-(P.width>>1); P.y=(h>>1)-(P.height>>1)
			  state.addChild( P );
			  }
	 /*  else {
		      var P=new TEXT();
			  P.x=(w>>1)-(P.width>>1);P.y=(h>>1)-(P.height>>1);
			  state.addChild( P );
			  }*/
	  state.mouseChildren=false;
	//  state.z=z
      return state;
 }
//_______________graph
private function Rcarre(c:int=0x00, a:Number=1,  w:int=1, h:int=1, r:int=5 ):Sprite { 	
	var g:Sprite=new Sprite()
	g.graphics.beginFill(c, a);
	g.graphics.drawRoundRect(0,0,w,h, r, r);
	g.graphics.endFill()
	return g  
}
//_______________________Bitmap Draw
private function bitmap( cible:* ):Bitmap {
	var Bitm:BitmapData= new BitmapData( cible.width, cible.height,true,0x00)
	Bitm.draw(cible)
	var b:Bitmap=new Bitmap(Bitm)
	b.x=cible.x; b.y=cible.y
	return b 
}

}}